/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.core.api;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.*;
import com.github.lvyanyang.model.IdBody;
import com.github.lvyanyang.model.IdsBody;
import com.github.lvyanyang.model.IdsStatusBody;
import com.xci.edu.core.entity.EduQuestionFavorite;
import com.xci.edu.core.filter.EduQuestionFavoriteFilter;
import com.xci.edu.core.service.EduQuestionFavoriteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 题库收藏接口
 * @author 马星俊 maxingjun@xci96716.com
 * @since 2020-12-24 14:51:30
 */
@Api(tags = "题库收藏接口")
@Authorize
@RestController
@RequestMapping(value = "/api/background/eduQuestionFavorite", produces = Const.PROJSON)
public class EduQuestionFavoriteApiController extends BaseController {
    /** 题库收藏服务 */
    @Resource private EduQuestionFavoriteService eduQuestionFavoriteService;

//    @ApiOperationSupport(order = 1)
//    @ApiOperation(value = "新建题库收藏")
//    //@Authorize(code = "background.eduQuestionFavorite.insert")
//    @PostMapping("/insert")
//    public BoolResult insert(@RequestBody EduQuestionFavorite entity) {
//        return eduQuestionFavoriteService.insert(entity);
//    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改题库收藏")
    //@Authorize(code = "background.eduQuestionFavorite.update")
    @PostMapping("/update")
    public BoolResult update(@RequestBody EduQuestionFavorite entity) {
        return eduQuestionFavoriteService.update(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改题库收藏状态")
    //@Authorize(code = "background.eduQuestionFavorite.updateStatus")
    @PostMapping(value = "/updateStatus")
    public BoolResult updateStatus(@RequestBody IdsStatusBody body) {
        eduQuestionFavoriteService.updateStatus(body.getIds(), body.getStatus());
        return BoolResult.success();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主键字符串删除题库收藏")
    //@Authorize(code = "background.eduQuestionFavorite.delete")
    @PostMapping(value = "/delete")
    public BoolResult delete(@RequestBody IdsBody body) {
        return eduQuestionFavoriteService.delete(body.getIds());
    }

    //@ApiOperationSupport(order = 4)
    //@ApiOperation(value = "检查题库收藏主键是否存在")
    //@PostMapping(value = "/existById")
    //public BoolResult existById(@RequestBody IdBody body) {
    //    return BoolResult.success(eduQuestionFavoriteService.existById(body.getId()));
    //}
    //@ApiOperationSupport(order = 5)
    //@ApiOperation(value = "检查题库收藏名称是否存在")
    //@PostMapping(value = "/existByName")
    //public BoolResult existByName(@RequestBody NameExcludeIdBody body) {
    //    return BoolResult.success(eduQuestionFavoriteService.existByName(body.getName(), body.getExcludeId()));
    //}
    //@ApiOperationSupport(order = 6)
    //@ApiOperation(value = "检查题库收藏编码是否存在")
    //@PostMapping(value = "/existByCode")
    //public BoolResult existByCode(@RequestBody CodeExcludeIdBody body) {
    //    return BoolResult.success(eduQuestionFavoriteService.existByCode(body.getCode(), body.getExcludeId()));
    //}

//    @ApiOperationSupport(order = 7)
//    @ApiOperation(value = "根据主键查询单个题库收藏")
//    //@Authorize(code = "background.eduQuestionFavorite.select")
//    @PostMapping("/selectById")
//    public BoolResult<EduQuestionFavorite> selectById(@RequestBody IdBody body) {
//        return BoolResult.success(eduQuestionFavoriteService.selectById(body.getId()));
//    }

    //@ApiOperationSupport(order = 8)
    //@ApiOperation(value = "根据编码查询单个题库收藏")
    ////@Authorize(code = "background.eduQuestionFavorite.select")
    //@PostMapping("/selectByCode")
    //public BoolResult<EduQuestionFavorite> selectByCode(@RequestBody CodeBody body) {
    //    return BoolResult.success(eduQuestionFavoriteService.selectByCode(body.getCode()));
    //}

    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "查询题库收藏分页列表")
    //@Authorize(code = "background.eduQuestionFavorite.select")
    @PostMapping("/selectPageList")
    public BoolResult<PageList<EduQuestionFavorite>> selectPageList(@RequestBody EduQuestionFavoriteFilter filter) {
        return BoolResult.success(eduQuestionFavoriteService.selectPageList(filter));
    }

    @ApiOperationSupport(order = 10, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "查询题库收藏列表")
    //@Authorize(code = "background.eduQuestionFavorite.select")
    @PostMapping("/selectList")
    public BoolResult<List<EduQuestionFavorite>> selectList(@RequestBody EduQuestionFavoriteFilter filter) {
        return BoolResult.success(eduQuestionFavoriteService.selectList(filter));
    }

    @ApiOperationSupport(order = 11, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "导出题库收藏列表")
    //@Authorize(code = "background.eduQuestionFavorite.export")
    @PostMapping(value = "/export", produces = {Const.PROOCTET, Const.PROJSON})
    public void export(@RequestBody EduQuestionFavoriteFilter filter) {
        XCI.exportExcel(eduQuestionFavoriteService.selectList(filter), EduQuestionFavorite.class, "题库收藏列表");
    }

    //@ApiOperationSupport(order = 12)
    //@ApiOperation(value = "获取题库收藏导出字段")
    //@PostMapping(value = "/exportNames")
    //public BoolResult<List<String>> exportNames() {
    //    return BoolResult.success(XCI.getExcelFiledNames(EduQuestionFavorite.class));
    //}
}